package com.ebupt.migu.music.commons.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @description: TODO
 * @author: liuyangyang@ebupt.com
 * @date: 2021/2/5 9:28
 */
public class TempData {

    /**
     * 手机号码校验
     */
    //原先正则规则：  ^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$
    //2022年最新正则：^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$
//    private static final Pattern pattern = Pattern.compile("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$");
    private static final Pattern pattern = Pattern.compile("^1[0-9]{10}$");


    /**
     * 对手机号码进行格式校验
     *
     * @param msisdn
     * @return
     */
    public static boolean isMsisdn(String msisdn) {
        Matcher matcher = pattern.matcher(msisdn);
        return matcher.matches();
    }

    public static void main(String[] args) {
        String path = "D:\\data\\P_3";
        String[] files = new File(path).list();
        Set<String[]> set = new HashSet<>();
        for (String file : files) {
            System.out.println(file);
            String filePath = path + "/" + file;
            // 文件中的用户
            List<String[]> msisdns = CSVUtils.csvRead(filePath);
            for (String[] msisdn : msisdns) {
                if (isMsisdn(msisdn[0]) && !set.contains(msisdn[0])) {
                    System.out.println(msisdn[0]);
                    set.add(msisdn);
                }
            }
        }
        List<String[]> data = new ArrayList<>(set);
        CSVUtils.csvWrite(path + "\\data_p3_2_without_BQ.csv", data);
        System.out.println("完成");
    }
}